package com.ruoyi.web.controller.riskAssessment;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.riskAssessment.domain.RiskAssessmentProgramInfo;
import com.ruoyi.riskAssessment.service.IRiskAssessmentProgramInfoService;
import com.ruoyi.riskAssessment.vo.RiskAssessmentProgramInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 危险源-事故发生的可能性(L)Controller
 *
 * @author lth
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/riskAssessment/info")
public class RiskAssessmentProgramInfoController extends BaseController
{
    @Autowired
    private IRiskAssessmentProgramInfoService riskAssessmentProgramInfoService;

    /**
     * 查询危险源-事故发生的可能性(L)列表
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskAssessmentProgramInfo riskAssessmentProgramInfo)
    {
        startPage();
        List<RiskAssessmentProgramInfo> list = riskAssessmentProgramInfoService.selectRiskAssessmentProgramInfoList(riskAssessmentProgramInfo);
        return getDataTable(list);
    }

    /**
     * 导出危险源-事故发生的可能性(L)列表
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:info:export')")
    @Log(title = "危险源-事故发生的可能性(L)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskAssessmentProgramInfo riskAssessmentProgramInfo)
    {
        List<RiskAssessmentProgramInfo> list = riskAssessmentProgramInfoService.selectRiskAssessmentProgramInfoList(riskAssessmentProgramInfo);
        ExcelUtil<RiskAssessmentProgramInfo> util = new ExcelUtil<RiskAssessmentProgramInfo>(RiskAssessmentProgramInfo.class);
        util.exportExcel(response, list, "危险源-事故发生的可能性(L)数据");
    }

    /**
     * 获取危险源-事故发生的可能性(L)详细信息
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(riskAssessmentProgramInfoService.selectRiskAssessmentProgramInfoById(id));
    }

    /**
     * 新增危险源-事故发生的可能性(L)
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:info:add')")
    @Log(title = "危险源-事故发生的可能性(L)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskAssessmentProgramInfo riskAssessmentProgramInfo)
    {
        return toAjax(riskAssessmentProgramInfoService.insertRiskAssessmentProgramInfo(riskAssessmentProgramInfo));
    }

    /**
     * 修改危险源-事故发生的可能性(L)
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:info:edit')")
    @Log(title = "危险源-事故发生的可能性(L)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskAssessmentProgramInfo riskAssessmentProgramInfo)
    {
        return toAjax(riskAssessmentProgramInfoService.updateRiskAssessmentProgramInfo(riskAssessmentProgramInfo));
    }

    /**
     * 删除危险源-事故发生的可能性(L)
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:info:remove')")
    @Log(title = "危险源-事故发生的可能性(L)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskAssessmentProgramInfoService.deleteRiskAssessmentProgramInfoByIds(ids));
    }


    /**
     * 通过schemeId获取List列表
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:info:query')")
    @GetMapping("/listById")
    public TableDataInfo listById(@RequestBody RiskAssessmentProgramInfoVo vo)
    {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<RiskAssessmentProgramInfo> list = riskAssessmentProgramInfoService.listById(vo);
        return getDataTable(list);
    }


}
